package net.huashitong.ssydt.provider.exam.service;

import net.huashitong.ssydt.exam.entity.SsExamTestRecord;
import net.huashitong.ssydt.exam.entity.vo.TestRecordsListInVO;
import net.huashitong.ssydt.provider.exam.mapper.SsExamTestRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.08.25
 */
@Service
@Transactional
public class SsExamTestRecordServiceImpl implements SsExamTestRecordService {

    private SsExamTestRecordMapper mapper;

    @Autowired
    public SsExamTestRecordServiceImpl(SsExamTestRecordMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public SsExamTestRecord getByStageAndScheduleIdAndState(Integer stageNumber, Long testScheduleId, String testState) {
        SsExamTestRecord ssExamTestRecord = new SsExamTestRecord();
        ssExamTestRecord.setStageNumber(stageNumber);
        ssExamTestRecord.setTestScheduleId(testScheduleId);
        ssExamTestRecord.setTestState(testState);
        return this.mapper.getByStageAndScheduleIdAndState(ssExamTestRecord);
    }

    @Override
    public void insertSelective(SsExamTestRecord record) {
        mapper.insertSelective(record);
    }

    @Override
    public void updateByPrimaryKeySelective(SsExamTestRecord record) {
        mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public SsExamTestRecord getById(Long recordId) {
        return mapper.selectByPrimaryKey(recordId);
    }

    @Override
    public List<SsExamTestRecord> queryByTestScheduleId(TestRecordsListInVO testRecordsListInVO) {
        return this.mapper.queryByTestScheduleId(testRecordsListInVO);
    }

    @Override
    public SsExamTestRecord getByStageAndScheduleId(int stageNumber, Long testScheduleId) {
        return this.getByStageAndScheduleIdAndState(stageNumber, testScheduleId, null);
    }

    @Override
    public int countSubmittedAll() {
        return this.mapper.countSubmittedAll();
    }

    @Override
    public int countSubmittedByLessOrEqualsCorrectNumber(Integer correctNumber) {
        return this.mapper.countSubmittedByLessOrEqualsCorrectNumber(correctNumber);
    }
}
